/**
 * Created with nova.
 * Date: 14-7-17
 * Time: 下午4:22
 */

$(function(){
        if($("#loading")[0])$("#loading").show();
        if($("#loading")[0])$("#loading")[0].addEventListener(touchEvents.touchmove, function(event){event.preventDefault();}, false);
        if($("#loading")[0])$("#loading")[0].addEventListener(touchEvents.touchstart, function(event){event.preventDefault();}, false);
        if($("#loadingObj")[0]) $("#loadingObj")[0].addEventListener(touchEvents.touchmove, function(event){event.preventDefault();}, false);
        if($("#loadingObj")[0]) $("#loadingObj")[0].addEventListener(touchEvents.touchstart, function(event){event.preventDefault();}, false);
        $("#lockDiv")[0].addEventListener(touchEvents.touchmove, function(event){event.preventDefault();}, false);
        $("#lockDiv")[0].addEventListener(touchEvents.touchstart, function(event){event.preventDefault();}, false);
});
var reg2=/\-?[0-9]+\.?[0-9]*/g;
var isLock=true;
var isBlur=false;
var touchEvents = {
    touchstart: "touchstart",
    touchmove: "touchmove",
    touchend: "touchend",
    initTouchEvents: function () {
        if (IsPC()) {
            this.touchstart = "mousedown";
            this.touchmove = "mousemove";
            this.touchend = "mouseup";
        }
    }
};

function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
        "SymbianOS", "Windows Phone",
        "iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}

requestAnimationFrame = window.requestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.msRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    function(callback) { setTimeout(callback, 1000 / 60); };

var sceneBgR=640/1008;

//support = $.support;
/*
for (key in support) {
    document.write('support.' + key + ' = ' + support[key] + '<br />');
}

for(var i=0;i<match.length;i++){
    //alert("--"+match[i]);
}
    */
var urlstr1=window.location.pathname;
var urlstrtmp=urlstr1.split("/");
var urlstr="http://"+window.location.host;
for(var i=0;i<urlstrtmp.length-1;i++){
    urlstr+=urlstrtmp[i]+"/";
}

var vx = navigator.userAgent.toLowerCase();

var mvx = parseInt(vx.match(/applewebkit\/([\d.]+)/)[1]);
//  var mvx1 = mvx.match(/([\d.]+)/);

var imgUrl = "http://weilink.huaxi100.com/spe/hx20/images/share2.jpg";
var lineLink = "http://weilink.huaxi100.com/spe/hx20/";
var descContent = "华西都市报20周年 有奖问答!";
var shareTitle = '华西都市报20周年 有奖问答';
var appid = '';
var isLast=false;

function shareFriend() {
    WeixinJSBridge.invoke('sendAppMessage',{
        "appid": appid,
        "img_url": imgUrl,
        "img_width": "200",
        "img_height": "200",
        "link": lineLink,
        "desc": descContent,
        "title": shareTitle
    }, function(res) {
        //_report('send_msg', res.err_msg);
        //alert(res.err_msg);
       // if(res.err_msg=="send_app_msg:confirm") {
            if(isLast) setTimeout(flipResult,1000);
            lineLink="http://weilink.huaxi100.com/spe/hx20";
        //}

    })
}
function shareTimeline() {
    WeixinJSBridge.invoke('shareTimeline',{
        "img_url": imgUrl,
        "img_width": "200",
        "img_height": "200",
        "link": lineLink,
        "desc": descContent,
        "title": shareTitle
    }, function(res) {
        //_report('timeline', res.err_msg);


       if(res.err_msg=="share_timeline:ok") {
           if(isLast) setTimeout(flipResult,1000);
       }
       lineLink="http://weilink.huaxi100.com/spe/hx20";
    });
}
function shareWeibo() {
    WeixinJSBridge.invoke('shareWeibo',{
        "content": descContent,
        "url": lineLink
    }, function(res) {
        //_report('weibo', res.err_msg);
    });
}
// 当微信内置浏览器完成内部初始化后会触发WeixinJSBridgeReady事件。
/*document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
    // 发送给好友
    WeixinJSBridge.on('menu:share:appmessage', function(argv){
        shareFriend();
    });
    // 分享到朋友圈
    WeixinJSBridge.on('menu:share:timeline', function(argv){
        shareTimeline();
    });
    // 分享到微博
    WeixinJSBridge.on('menu:share:weibo', function(argv){
        shareWeibo();
    });
}, false);*/



var flipResult=function(){
    $('#shareR').show();
    TweenMax.set($('#shareR'),{rotationY:120,alpha:0,transformPerspective:600,transformOrigin:"center center"});
    TweenMax.to($('#shareR'),1,{rotationY:0,alpha:1,transformPerspective:600,transformOrigin:"center center",ease:Quart.easeInOut});
}

var $_GET = (function(){
    var url = window.document.location.href.toString();
    var u = url.split("?");
    if(typeof(u[1]) == "string"){
        u = u[1].split("&");
        var get = {};
        for(var i in u){
            var j = u[i].split("=");
            get[j[0]] = j[1];
        }
        return get;
    } else {
        return {};
    }
})();
var isUnlock=false;
var isScreenLock=false;
var browser={
    versions:function(){
        var u = navigator.userAgent, app = navigator.appVersion;
        return {         //移动终端浏览器版本信息
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
            iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf('iPad') > -1, //是否iPad
            webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
        };
    }(),
    language:(navigator.browserLanguage || navigator.language).toLowerCase()
}
